package org.techmore.bussiness;

import java.util.List;

import org.techmore.hakka.R;
import org.techmore.valueobject.VisitorListViewVO;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

public class VisitorSoundActivityDataHandler {

	private static VisitorSoundActivityDataHandler visitorSoundActivityDataHandler = new VisitorSoundActivityDataHandler();

	public static VisitorSoundActivityDataHandler getInstance() {
		return visitorSoundActivityDataHandler;
	}
	


	public class VisitorSoundListViewAdapter extends BaseAdapter {

		private Context context;
		private List<VisitorListViewVO> list = null;
		
		private View visitorListViewContent = null;
		private Button visitorListViewButton = null;
		private TextView visitorListViewSoundWord = null;
		private TextView visitorListViewSoundMark = null;

		public VisitorSoundListViewAdapter(Context context, List<VisitorListViewVO> list) {
			this.context = context;
			this.list = list;
		}

		@Override
		public int getCount() {
			return list.size();
		}

		@Override
		public Object getItem(int arg0) {
			return list.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(int arg0, View arg1, ViewGroup arg2) {
			visitorListViewContent = LayoutInflater.from(context).inflate(R.layout.visitorlistview_content, null);
			
			visitorListViewButton = (Button) visitorListViewContent.findViewById(R.id.visitorListViewButton);
			visitorListViewSoundWord = (TextView) visitorListViewContent.findViewById(R.id.visitorListViewSoundWord);
			visitorListViewSoundMark = (TextView) visitorListViewContent.findViewById(R.id.visitorListViewSoundMark);
			
			visitorListViewSoundWord.setText(list.get(arg0).getSoundWord());
			visitorListViewSoundMark.setText(list.get(arg0).getSoundMark());
			final int index = arg0;
			visitorListViewButton.setOnClickListener(new View.OnClickListener() {
				@Override
				public void onClick(View v) {
					System.out.println(list.get(index).getSoundName());
				}
			});
			return visitorListViewContent;
		}
	}

}
